package com.animee.jiujiangdict.utils;
import android.content.Context;
import android.content.res.AssetManager;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/*
* 读取Assets文件夹下的内容的工具类
* */
public class AssetsUtils {
    /*
    * 将assets文件夹下，指定文件内容转换成字符串的，保存在内容中
    * */
    public static String getAssetsContent(Context context,String filename){
        AssetManager manager = context.getResources().getAssets();
        try {
            InputStream is = manager.open(filename);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int hasRead = 0;
            byte[]buf = new byte[1024];
            while (true){
                hasRead = is.read(buf);
                if (hasRead==-1){
                    break;
                }else{
                    baos.write(buf,0,hasRead);
                }
            }
            return baos.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
